$(document).ready(function(){
	init();
});

function init(){
	window.ajaxCounter = 1;
    $('.button').button();
    $('#continue').click(function(){continueOnTrail()})

    $('.ui-widget-overlay').live('click', function() {
     });   
    

}

function continueOnTrail() {
	window.ajaxCounter += 1;
	makeWagonGo();
	d = new Date();
	$.ajax({url:$('#continue').attr('url') + '?r=' + (d.getTime()),
		type: "GET",
		dataType: 'json',
		success:function(info){
//			$.notifyBar({
//				html: 'Successfully changed rations to "' + info + '"',
//				delay: 2000,
//				animationSpeed: "normal",
//				cls: "success"
//			});
			if ('url' in info){
				window.location = info['url'];
			} else {
				$('#distTraveled').html(info['distTraveled']);
				$('#currFood').html(info['currFood']);
			}
		},
		error:function(){
			$.notifyBar({
				html: 'Unable to continue',
				delay: 2000,
				animationSpeed: "normal",
				cls: "error"
			});
		}
	});
}

function makeWagonGo(){
	var wagon = $('#wagonImg');
	if (wagon.css('padding-left').replace(/px/i,'') < 500){
		wagon.animate({ 
            'padding-left': '+=200px', 
        }, 1000);
	}
	else{
		wagon.animate({ 
            'padding-left': '20px', 
        }, 0);
	}
	 	
}
